const app = getApp()
const $ = app.globalData
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		input: "",
		search_result: [],
		colorArr: ["#EE2C2C", "#ff7070", "#EEC900", "#4876FF", "#ff6100",
			"#7DC67D", "#E17572", "#7898AA", "#C35CFF", "#33BCBA", "#C28F5C",
			"#FF8533", "#6E6E6E", "#428BCA", "#5cb85c", "#FF674F", "#E9967A",
			"#66CDAA", "#00CED1", "#9F79EE", "#CD3333", "#FFC125", "#32CD32",
			"#00BFFF", "#68A2D5", "#FF69B4", "#DB7093", "#CD3278", "#607B8B"
		]
	},
	bindClear: function() {
		this.setData({
			input: "",
			search_result: []
		});
	},
	bindInput: function(e) {
		this.setData({
			input: e.detail.value,
			search_result: [0, 1, 2, 3, 4].slice(0, e.detail.value.length)
		});
	},
	// 进店
	goshop: function(options) {
		var shopid = options.currentTarget.dataset.id
		wx.navigateTo({
			url:'../shop/shop?id='+shopid
		})
	},
	// 点击商品
	clickGood: function(options) {
		var goodsId = options.currentTarget.dataset.id
		var shopid = options.currentTarget.dataset.shopid
		var shopname = options.currentTarget.dataset.shopname
		wx.navigateTo({
			url: "../details/details?id=" + goodsId + "&shopid=" + shopid + "&shopname="+shopname
		})
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		var that = this
		let colorLen = this.data.colorArr.length
		var thisid = options.id
		
			wx.request({
				url: $.AdminUrl + "/YApi/getShopListById",
				data: {
					goodsid: thisid
				},
				success: function(data) {
					var dataa = data.data.obj
					for (var i = 0; i < dataa.length; i++) {
						var random = Math.floor(Math.random() * colorLen + 0)
						dataa[i]['color'] = that.data.colorArr[random]
					}
					that.setData({
						business: dataa,
						thisid:thisid
					})
					console.log(dataa)
				}
			})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},
	// 分享转发
		onShareAppMessage: function() {
			var that = this
			var userinfo = wx.getStorageSync('userinfo')
			return {
				title: '优悦购生活管家',
				path: '/pages/shopping/business/business?userid='+userinfo.loginname+"&id="+that.data.thisid,
				success: (res) => {
					console.log("转发成功", res);
				},
				fail: (res) => {
					console.log("转发失败", res);
				}
			}
		}
})
